<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>⿏标点击⻚⾯出现随机颜⾊的⽂字，出现之后向上淡出</title>
  <style>
    p {
      font-size: 18px;
      font-weight: bolder;
    }
  </style>
</head>
<body>
  <p></p>
  <script>
    var arrColor = ['red', 'pink', 'yellow', 'green', 'blue', 'black', 'orange']
    var arrText = ['你好', '♂', '哲学', '动次大', '欧耶', '罚款哟', '西内']
    // 设置随机数
    function getRandom(m, n) {
      return Math.floor(Math.random() * (n - m + 1)) + m
    }
    // 点击页面
    document.body.onclick = function() {
      var p = document.querySelector('p')
      var i;
      var j;
      for(i = 0; i < arrColor.length; i++){}
      for(j = 0; j < arrText.length; j++){}
      // -1 是因为只有6个
      var resColor = getRandom(0, i - 1)
      var resText = getRandom(0, j - 1)
      // console.log(resColor, resText)
      p.style.color = arrColor[resColor]
      p.innerText = arrText[resText]

      // 设置淡出
      var time = 1
      set = setInterval(function(){
        p.style.opacity = time
        time -= 0.1
      }, 200)
      // 设置停止效果
      // if(time == 0) {
      //   console.log('aaa');
      //   clearInterval(set)
      // }
    }
    
  </script>
</body>
</html>